package com.wms.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wms.common.QueryPageParam;
import com.wms.common.Result;
import com.wms.entity.Goodstype;
import com.wms.entity.Notice;
import com.wms.service.GoodstypeService;
import com.wms.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 系统公告表 前端控制器
 * </p>
 *
 * @author wms
 * @since 2025-04-22
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;
    //新增
    @PostMapping("/save")
    public Result save(@RequestBody Notice notice ){
        return noticeService.save(notice)?Result.suc():Result.fail();
    }
    //更新
    @PostMapping("/update")
    public Result update(@RequestBody Notice notice){
        return noticeService.updateById(notice)?Result.suc():Result.fail();
    }
    //删除
    @GetMapping("/del")
    public Result del(@RequestParam String id){
        return noticeService.removeById(id)?Result.suc():Result.fail();
    }

    @PostMapping("/listPage")
    //public List<Storage> listPage(@RequestBody HashMap map) {
    public Result listPage(@RequestBody QueryPageParam query) {
        //System.out.println(query);
        HashMap param = query.getParam();
        String title = (String)param.get("title");
        String content = (String)param.get("content");

        System.out.println("name==="+param.get("name"));
        //System.out.println(param.get("no"));

        Page<Notice> page=new Page();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<Notice> lambdaQuery = new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(title) && !"null".equals(title)){
            lambdaQuery.like(Notice::getTitle,title);
        }
        if(StringUtils.isNotBlank(content) && !"null".equals(content)){
            lambdaQuery.like(Notice::getContent,content);
        }


        IPage result = noticeService.pageCC(page,lambdaQuery);

        return Result.suc(result.getRecords(),result.getTotal());
    }

    @GetMapping("/list")
    public Result list(){
        List list = noticeService.lambdaQuery().list();
        return Result.suc(list);
    }

}
